package com.xxzx.publicprevention.service.impl;


import com.xxzx.publicprevention.mapper.GeoZhyfqDao;
import com.xxzx.publicprevention.pojo.GeoZhyfq;
import com.xxzx.publicprevention.service.GeoZhyfqService;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;
import java.io.InputStream;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.List;

/**
 * (GeoZhyfq)表服务实现类
 *
 * @author makejava
 * @since 2020-11-12 12:56:42
 */
@Service("geoZhyfqService")
public class GeoZhyfqServiceImpl implements GeoZhyfqService {
    @Resource
    private GeoZhyfqDao geoZhyfqDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public GeoZhyfq queryById(Integer id) {


        GeoZhyfq geoZhyfq = this.geoZhyfqDao.queryById(id);


        return geoZhyfq;

    }

    @Override
    public List<GeoZhyfq> gis_Contains(String coords) {
        return geoZhyfqDao.gis_Contains(coords);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<GeoZhyfq> queryAllByLimit(int offset, int limit) {
        return this.geoZhyfqDao.queryAllByLimit(offset, limit);
    }

    @Override
    public List<GeoZhyfq> queryAll(GeoZhyfq geoZhyfq) {
        return this.geoZhyfqDao.queryAll(geoZhyfq);


    }

    /**
     * 新增数据
     *
     * @param geoZhyfq 实例对象
     * @return 实例对象
     */
    @Override
    public GeoZhyfq insert(GeoZhyfq geoZhyfq) {
        this.geoZhyfqDao.insert(geoZhyfq);
        return geoZhyfq;
    }

    /**
     * 修改数据
     *
     * @param geoZhyfq 实例对象
     * @return 实例对象
     */
    @Override
    public GeoZhyfq update(GeoZhyfq geoZhyfq) {
        this.geoZhyfqDao.update(geoZhyfq);
        return this.queryById(geoZhyfq.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.geoZhyfqDao.deleteById(id) > 0;
    }

    @Override
    public List<GeoZhyfq> getZhyfqByKeywords(String keywords) {
        return this.geoZhyfqDao.getZhyfqByKeywords(keywords);
    }

    @Override
    public List<String> getYfqYear() {
        List<String> list = new ArrayList<>();
        GeoZhyfq geoZhyfq = new GeoZhyfq();
        List<GeoZhyfq> zhyfqs = queryAll(geoZhyfq);

        if (list.size() == 0) {
            list.add(zhyfqs.get(0).getNd());
        }

        for (GeoZhyfq c : zhyfqs) {

            boolean flag = true;
            if (c.getNd().trim().equals("")) {
                flag = false;
            } else {
                for (String k : list) {
                    if (k.equals(c.getNd())) {
                        flag = false;
                    }
                }

            }
            if (flag) {
                list.add(c.getNd());
            }

        }


        return list;
    }

    @Override
    public List<GeoZhyfq> getZhyfqByNd(String nd) {
        List<GeoZhyfq> byNd = new ArrayList<>();
        if (nd.equals("1970")) {
            GeoZhyfq geoZhyfq = new GeoZhyfq();
            byNd = this.geoZhyfqDao.queryAll(geoZhyfq);
        } else {
            byNd = this.geoZhyfqDao.getZhyfqByNd(nd);
        }

        return byNd;


    }

    @Override
    public List<GeoZhyfq> getZhyfqByNdAndKeywords(String nd, String keywords) {
        return this.geoZhyfqDao.getZhyfqByNdAndKeywords(nd, keywords);
    }


}

